// vim:set tabstop=4 shiftwidth=4 softtabstop=4 expandtab foldcolumn=1 foldmethod=marker foldclose=all:
/**
 * Project: 5anet
 * File:    src/com/m5anet/tag/SetEnv.java
 *
 * get the variable from serval scope and put them to page
 *
 * I write this tag, for get the variable from serval scope, and
 * put them into page scope, let us can use them directory.
 * like <% = variablename %>
 *
 *
 * Author:      $Author: hylinux $
 * Date:        $Date: 2008-01-23 02:18:46 +0000 (Wed, 23 Jan 2008) $
 * Reversion:   $Rev: 13 $
 * Id:          $Id: SetEnv.java 13 2008-01-23 02:18:46Z hylinux $
 */
package com.m5anet.tag;

import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.BodyTagSupport;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;

public class SetEnv extends BodyTagSupport {

    public void setScope(String scope) {
        if ( scope != "application" &&
                scope != "session" && scope != "request" ) {
            this.scope = "application";
        } else {
            this.scope = scope;
        }
    }

    public String getScope() {
        return this.scope;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return this.id;
    }


    public int doEndTag() {
        String value = null;

        if ( scope == "application" ) {
            value = (String)pageContext.getServletContext().getAttribute(name);
        } else if ( scope == "request" ) {
            value = (String)pageContext.getRequest().getAttribute(name);
        } else if ( scope == "session" ) {
            value = (String)pageContext.getSession().getAttribute(name);
        }

        pageContext.setAttribute(this.id, value);

        return EVAL_PAGE;
    }




    private String scope = "request";
    private String name = null;
    private String id = null;
    private String idValue = null;

}
